//
//  LicensePlateTableViewCell.m
//  XinKaiFa55like
//
//  Created by junseek on 2017/3/22.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "LicensePlateTableViewCell.h"
#import "UILabel+atrribulttext.h"

@interface LicensePlateTableViewCell (){    //
    
    NSIndexPath *tempIndexPath;
    NSDictionary *tempDic;
    
    UIView *viewBg;
    UILabel *lblTitle;
    UILabel *lblContent;
    UIImageView *imageIcon;
    UILabel *lblDate;
    
    UIImageView *imageRedTip;
    UIView *viewLine;
    
    UILabel *lblMoney;
    UILabel *lblStatus;
}

@end
@implementation LicensePlateTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        viewBg=[[UIView alloc]initWithFrame:CGRectMake(10, 5, kScreenWidth-20, 50)];
        [viewBg setBackgroundColor:RGBCOLOR(255, 255, 255)];
        [self addSubview:viewBg];
        [[Utility Share] viewLayerRound:viewBg borderWidth:1 cornerRadius:4 borderColor:[UIColor clearColor]];
        
        lblTitle=[RHMethods labelWithFrame:CGRectMake(10, 10, W(viewBg)-30, 0) font:fontTitle color:rgbTitleColor text:@""];
        [viewBg addSubview:lblTitle];
        lblTitle.autoresizingMask=UIViewAutoresizingFlexibleWidth;
        
        lblMoney=[RHMethods labelWithFrame:CGRectMake(0, 10, 0, 20) font:fontTxtContent color:rgbpublicColor text:@"" textAlignment:NSTextAlignmentRight];
        [viewBg addSubview:lblMoney];
        lblMoney.hidden=YES;
        
        imageRedTip=[RHMethods imageviewWithFrame:CGRectMake(W(viewBg)-17, 7, 7, 7) defaultimage:@"redTip070116" contentMode:UIViewContentModeScaleAspectFit];
        [viewBg addSubview:imageRedTip];
        imageRedTip.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
        
        lblContent=[RHMethods labelWithFrame:CGRectMake(10, 10, W(viewBg)-20, 20) font:fontTxtContent color:rgbTxtDeepGray text:@""];
        [viewBg addSubview:lblContent];
        lblContent.autoresizingMask=UIViewAutoresizingFlexibleWidth;
        
        imageIcon=[RHMethods imageviewWithFrame:CGRectMake(10, 10, 8, 20) defaultimage:@"timeicon" contentMode:UIViewContentModeScaleAspectFit];
        [viewBg addSubview:imageIcon];
        
        lblDate=[RHMethods labelWithFrame:CGRectMake(23, 10, W(viewBg)-33, 20) font:fontSmallTitle color:rgbTxtGray text:@""];
        [viewBg addSubview:lblDate];
        
        lblStatus=[RHMethods labelWithFrame:CGRectMake(W(viewBg)-100, 0, 90, 20) font:fontTxtContent color:rgbpublicColor text:@"" textAlignment:NSTextAlignmentRight];
        [viewBg addSubview:lblStatus];
        
        viewLine=[RHMethods lineViewWithFrame:CGRectMake(0, 0, kScreenWidth, 0.5)];
        [self addSubview:viewLine];
        viewLine.hidden=YES;
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return self;
}

//内容更新
-(void)setValueForDictionary:(NSDictionary *)dic indexPath:(NSIndexPath *)indexPath type:(NSString *)strType{
    [self setValueForDictionary:dic indexPath:indexPath type:strType searchKey:@""];
}
-(NSInteger)setValueForDictionary:(NSDictionary *)dic indexPath:(NSIndexPath *)indexPath type:(NSString *)strType searchKey:(NSString *)strKey{
    tempIndexPath=indexPath;
    tempDic=dic;
    lblStatus.hidden=YES;
    if ([strType isEqualToString:@"crm"]) {
        NSString *strTitle=[NSString stringWithFormat:@"%@",[dic valueForJSONStrKey:[[Utility Share] userIsADD]?@"title":@"stitle"]];
        lblTitle.text=strTitle;
        lblMoney.hidden=NO;
        imageRedTip.hidden=YES;
        lblMoney.text=[NSString stringWithFormat:@"￥%@",[dic valueForJSONStrKey:@"price"]];
        float fw=[lblMoney sizeThatFits:CGSizeMake(MAXFLOAT , 20)].width;
        lblMoney.frame=CGRectMake(W(viewBg)-10-fw, 10, fw, 20);
        lblTitle.frameWidth=X(lblMoney)-20;
        
        lblContent.text=[NSString stringWithFormat:@"%@ | %@ | %@",[dic valueForJSONStrKey:@"cname"],[dic valueForJSONStrKey:@"regtime"],[dic valueForJSONStrKey:@"regcapital"]];
        
        if ([strKey notEmptyOrNull]) {
            NSArray *arrayKey=[strKey componentsSeparatedByString:@" "];
            for (NSString *keys in arrayKey) {
                [lblTitle setColor:rgbpublicColor contenttext:keys];
                [lblContent setColor:rgbpublicColor contenttext:keys];
            }
        }
        
        lblDate.text=[dic valueForJSONStrKey:@"ctime"];//[[Utility Share] timeToTimestamp:[dic valueForJSONStrKey:@"ctime"]];//@"2017-03-23 12:12";
        //kScreenWidth-50
        float fh=[lblTitle sizeThatFits:CGSizeMake(X(lblMoney)-20, MAXFLOAT)].height;
        lblTitle.frameHeight=fh>20?40:20;
        lblContent.frameY=YH(lblTitle);
        lblDate.frameY=YH(lblContent);
        imageIcon.frameY=YH(lblContent);
        
        if ([strType isEqualToString:@"Extension"]) {
            //55
            viewBg.frame=CGRectMake(0, 0, kScreenWidth,H(lblTitle)+55 );
            viewLine.hidden=NO;
            viewLine.frameY=H(viewBg)-0.5;
        }else{
            //55
            viewBg.frameHeight=H(lblTitle)+55;
        }

        return YH(viewBg)+5;
    }else{
        NSString *strTitle=[NSString stringWithFormat:@"%@",[dic valueForJSONStrKey:[[Utility Share] userIsADD]?@"title":@"stitle"]];
        lblTitle.text=strTitle;
        
        imageRedTip.hidden=![[dic valueForJSONStrKey:@"isread"] isEqualToString:@"0"];
        
        lblContent.text=[NSString stringWithFormat:@"%@ | %@ | %@ | %@",[dic valueForJSONStrKey:@"cname"],[dic valueForJSONStrKey:@"regtime"],[dic valueForJSONStrKey:@"regcapital"],[dic valueForJSONStrKey:@"contact"]];//,@"中外合资",@"2014年",@"2000万人民币",@"ZhangSan"
        
        if ([strKey notEmptyOrNull]) {
            NSArray *arrayKey=[strKey componentsSeparatedByString:@" "];
            for (NSString *keys in arrayKey) {
                [lblTitle setColor:rgbpublicColor contenttext:keys];
                [lblContent setColor:rgbpublicColor contenttext:keys];
            }
        }
        
        lblDate.text=[dic valueForJSONStrKey:@"ctime"];//[[Utility Share] timeToTimestamp:[dic valueForJSONStrKey:@"ctime"]];//@"2017-03-23 12:12";
        
        float fh=[lblTitle sizeThatFits:CGSizeMake(kScreenWidth-50, MAXFLOAT)].height;
        lblTitle.frameHeight=fh>20?40:20;
        lblContent.frameY=YH(lblTitle);
        lblDate.frameY=YH(lblContent);
        imageIcon.frameY=YH(lblContent);
        
        if ([strType isEqualToString:@"Extension"]) {
            //55
            viewBg.frame=CGRectMake(0, 0, kScreenWidth,H(lblTitle)+55 );
            viewLine.hidden=NO;
            viewLine.frameY=H(viewBg)-0.5;
            lblDate.text=[[Utility Share] timeToTimestamp:[dic valueForJSONStrKey:@"ctime"]];
        }else{
            //55
            viewBg.frameHeight=H(lblTitle)+55;
        }
        if ([strType isEqualToString:@"showSatus"]) {
            //显示状态
            lblStatus.hidden=NO;
            lblStatus.frameY=Y(lblDate);
            lblStatus.text=[[dic valueForJSONStrKey:@"isopen"] isEqualToString:@"0"]?@"未审核":@"已审核";
        }

    }

    return 0;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
